function isChineseAndMark(text, isMark) {
    if (isMark) {
        return /^[\u4e00-\u9fa5$：？！。!_-，——,:《》]+$/.test(text);
    }
    return /^[\u4e00-\u9fa5]+$/.test(text);
}
/**
 * 判断是否为中文字符串
 * @param {String} text
 * @param {Function} iterate // 回调函数
 * @param {Boolean} isMark // 是否包含标点符号
 * @param {Object} context
 * @returns {Array}
 */
function chineseCharacters(text, iterate, isMark = false, context) {
    const flag = isChineseAndMark(text, isMark)
    let result = []
    if (flag) {
        result = [text]
    } else {
        let chineseChars = [];
        for (let i = 0; i < text.length; i++) { 
            const char = text[i];

            if (isChineseAndMark(char, isMark)) {
                chineseChars.push(char);
            } else {
                if (chineseChars.length > 0) {
                    result.push(chineseChars.join(''));
                    chineseChars = [];
                }
            }
        }
    }

    result.map(iterate, context);

    return result;
}

module.exports = chineseCharacters